
* Estimate non linear effects of pollution


***Inputs: 
* $Data/GameUserWPdaily_norm.dta
* $Data/maxmindirectionsmonth_zip260.dta

***Outputs: 
* $Results/pmnonlinearnarrow90.png


	
	use $Data/GameUserWPdaily_norm.dta, clear
	
	gen month = month(date)

		
	gen zip2 = int( zip/10)
	
	merge m:1 zip2 month using $Data/maxmindirectionsmonth_zip260.dta
	
	keep if _merge ==3
	
	
	gen monthyear = mofd(date)

	gen highpm =  weighted_dailypm > 25 & weighted_dailypm<. 

	gen moderate = weighted_dailypm > 12 & weighted_dailypm<. 
	
	gen unhealthysensitive = weighted_dailypm > 35 & weighted_dailypm<. 
	
	gen unhealthy = weighted_dailypm > 55.5  & weighted_dailypm<. 

	gen veryunhealthy = weighted_dailypm > 150.5  & weighted_dailypm<. 

	gen hazardous = weighted_dailypm > 250  & weighted_dailypm<. 

	
	
	egen cut_winddirection = cut(median_closestwind), at(0(60)360)
	replace cut_winddirection = 0 if median_closestwind ==360

	
	
	gen maxzipwind = (cut_winddirection ==maxdirection )
	replace maxzipwind = . if maxdirection==.
	
	keep if maxzipwind<. 
	
	
	egen cut_temp = cut(weighted_temperature), at(-40(10)40)

	
			 gen referencepm =  weighted_dailypm <= 5 


		 
		 
		 
		 
		 forval pm = 5(5)55 {
		 
		 local pmnext = `pm' + 5
		 
gen pmbin`pm' = weighted_dailypm > `pm' & weighted_dailypm<= `pmnext'
			label variable pmbin`pm' "`pm'"	 
		 
		 ivreghdfe norm_score (pmbin`pm' =maxzipwind )  weighted_wind_speed weighted_precipitation if (pmbin`pm'==1  | referencepm==1) , absorb(anon_id monthyear cut_temp) cluster(anon_id monthyear)

		eststo nonlinearpm`pm'
		 
		 
		 
		 }
		 
		 
	
		 
  coefplot (nonlinearpm5, keep(pmbin5) ciopts(recast(rcap) lcolor(green%30))  mcolor(green) msymbol(diamond) msize(medium)) ///
    (nonlinearpm10, keep(pmbin10) ciopts(recast(rcap) lcolor(green%30)) mcolor(green) msymbol(diamond) msize(medium))  ///
	(nonlinearpm15, keep(pmbin15) ciopts(recast(rcap) lcolor(gold%30)) mcolor(gold) msymbol(diamond) msize(medium))  ///
	(nonlinearpm20, keep(pmbin20) ciopts(recast(rcap) lcolor(gold%30)) mcolor(gold) msymbol(diamond) msize(medium))  ///
	(nonlinearpm25, keep(pmbin25) ciopts(recast(rcap) lcolor(gold%30)) mcolor(gold) msymbol(diamond) msize(medium))  ///
   (nonlinearpm30, keep(pmbin30) ciopts(recast(rcap) lcolor(gold%30)) mcolor(gold) msymbol(diamond) msize(medium))  ///
	(nonlinearpm35, keep(pmbin35) ciopts(recast(rcap) lcolor(orange%30)) mcolor(orange) msymbol(diamond) msize(medium))  ///
	///
		 ,    vertical levels(90)   nooffsets  legend(off)  yline(0, lcolor(gs0%10)) xtitle("PM 2.5 (5 {&mu}g/m{superscript:3} bins)")
		 
		 
		 graph export $Results/pmnonlinearnarrow90.png, replace
		 
	
	
	
	
	
	
	
	
	
